package cn.mihoyo.user.dto;

import cn.mihoyo.base.util.MD5Utils;
import cn.mihoyo.base.util.StrUtils;
import cn.mihoyo.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class EmailRegisterDto {
    @NotBlank(message = "邮箱不能为空")
    private String email;
    @NotBlank(message = "短信验证码不能为空")
    private String emailCodeValue;
    @NotBlank(message = "密码不能为空")
    private String password;
    @NotBlank(message = "二次密码不能为空")
    private String passwordRepeat;

    public User getUser() {
        String salt = StrUtils.getComplexRandomString(32);
        String pwd = MD5Utils.encrypByMd5(salt+this.password);
        return User.builder()
                .username(this.email)
                .email(this.email)
                .salt(salt)
                .password(pwd)
                .state(1)
                .createtime(new Date())
                .build();
    }
}
